﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QRCode2.Models;

namespace QRCode2.Controllers
{
    public class AgentCommentController : Controller
    {
        private AgentCommentDBContext db = new AgentCommentDBContext();

        //
        // GET: /AgentComment/

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Index()
        {
            return View(db.AgentComments.ToList());
        }

        //
        // GET: /AgentComment/Details/5

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Details(int id = 0)
        {
            AgentComment agentcomment = db.AgentComments.Find(id);
            if (agentcomment == null)
            {
                return HttpNotFound();
            }
            return View(agentcomment);
        }

        //
        // GET: /AgentComment/Create

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /AgentComment/Create

        [Authorize(Roles = "RealEstateAgent")]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(AgentComment agentcomment)
        {
            if (ModelState.IsValid)
            {
                db.AgentComments.Add(agentcomment);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(agentcomment);
        }

        //
        // GET: /AgentComment/Edit/5

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Edit(int id = 0)
        {
            AgentComment agentcomment = db.AgentComments.Find(id);
            if (agentcomment == null)
            {
                return HttpNotFound();
            }
            return View(agentcomment);
        }

        //
        // POST: /AgentComment/Edit/5

        [Authorize(Roles = "RealEstateAgent")]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(AgentComment agentcomment)
        {
            if (ModelState.IsValid)
            {
                db.Entry(agentcomment).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(agentcomment);
        }

        //
        // GET: /AgentComment/Delete/5

        [Authorize(Roles = "RealEstateAgent")]
        public ActionResult Delete(int id = 0)
        {
            AgentComment agentcomment = db.AgentComments.Find(id);
            if (agentcomment == null)
            {
                return HttpNotFound();
            }
            return View(agentcomment);
        }

        //
        // POST: /AgentComment/Delete/5

        [Authorize(Roles = "RealEstateAgent")]
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            AgentComment agentcomment = db.AgentComments.Find(id);
            db.AgentComments.Remove(agentcomment);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}